package com.EVO.controller;

import com.EVO.dao.UserDao;
import com.EVO.entity.Users;
import com.EVO.util.Util;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Enumeration;

public class UserAddServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName,password,sex,email;
        UserDao dao = new UserDao();
        Users user = null;
        int result = 0;
        PrintWriter out = null;
        response.setContentType("text/html;charset=utf-8");
        userName = request.getParameter("username");
        password = request.getParameter("password");
        sex = request.getParameter("sex");
        email = request.getParameter("email");
        user = new Users(null,userName,password,sex,email);
        Date startDate = new Date();
        result = dao.add(user,request);
        Date endDate = new Date();
        System.out.println("消耗的时间："+(endDate.getTime() - startDate.getTime())+"毫秒");

        out = response.getWriter();
        if(result == 1){
            out.print("<center><font style='color:red;font-size:40px'>恭喜您注册成功！！</font></center>");
        }else{
            out.print("<center><font style='color:red;font-size:40px'>注册失败，请检查您输入的信息</font></center>");
        }
    }
}
